//
//  ShelfViewController.m
//  JianChaRiBao
//
//  Created by yuzhou on 13-5-9.
//  Copyright (c) 2013年 wzyk. All rights reserved.
//

#import "ShelfViewController.h"
#import "MagazineShelfViewController.h"
#import "ListenShelfViewController.h"
#import "NovelShelfViewController.h"
#import "NewspaperShelViewController.h"

@interface ShelfViewController ()
{
    NewspaperShelViewController *newspaperShelViewController;
    MagazineShelfViewController *magazineShelfViewController;
    ListenShelfViewController *listenShelfViewController;
    NovelShelfViewController *novelShelfViewController;
}
@end

@implementation ShelfViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.frame = self.parentViewController.view.bounds;
    
    if (newspaperShelViewController == nil) {
        newspaperShelViewController = [[NewspaperShelViewController alloc] initWithNibName:@"NewspaperShelViewController" bundle:nil];
    }
    [self addChildViewController:newspaperShelViewController];
    
    [self switchToIndex:kNewsIndex];
}

- (void)switchToIndex:(int)index
{
    switch (index) {
//        case kNewsIndex:{
//            if (newspaperShelViewController == nil) {
//                newspaperShelViewController = [[NewspaperShelViewController alloc] initWithNibName:@"NewspaperShelViewController" bundle:nil];
//            }
//            [self addChildViewController:newspaperShelViewController];
//            [self transitionFromViewController:self.currentViewController toViewController:newspaperShelViewController duration:0 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
//        }
//            break;
        case kMagazineIndex:{
            if (magazineShelfViewController == nil) {
                magazineShelfViewController = [[MagazineShelfViewController alloc] initWithNibName:@"MagazineShelfViewController" bundle:nil];
            }
            [self addChildViewController:magazineShelfViewController];
            [self transitionFromViewController:self.currentViewController toViewController:magazineShelfViewController duration:0 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
        }
            break;
        case kListenIndex:{
            if (listenShelfViewController == nil) {
                listenShelfViewController = [[ListenShelfViewController alloc] initWithNibName:@"ListenShelfViewController" bundle:nil];
            }
            [self addChildViewController:listenShelfViewController];
            [self transitionFromViewController:self.currentViewController toViewController:listenShelfViewController duration:0 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
        }
            break;
        case kNovelIndex:{
            if (novelShelfViewController == nil) {
                novelShelfViewController = [[NovelShelfViewController alloc] initWithNibName:@"NovelShelfViewController" bundle:nil];
            }
            [self addChildViewController:novelShelfViewController];
            [self transitionFromViewController:self.currentViewController toViewController:novelShelfViewController duration:0 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
        }
            break;
        default:{
            if (magazineShelfViewController == nil) {
                magazineShelfViewController = [[MagazineShelfViewController alloc] initWithNibName:@"MagazineShelfViewController" bundle:nil];
            }
            [self addChildViewController:magazineShelfViewController];
            [self transitionFromViewController:self.currentViewController toViewController:magazineShelfViewController duration:0 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
        }
            break;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
